﻿using System; 
using System.Reflection; 
namespace docmgr.Model { 
                           
	public class Document{ 	

		#region 私有属性成员 
		
		int m_ID; //ID 
		string m_DocName; //文件标题 
		string m_Remark; //Remark 
		DateTime m_RegDate; //处理日期 
		int m_UserID; //责任人 
		int m_SysSerialNumber; //编号 
		string m_DocSerialNumber; //发文字号 
		string m_SecretLevel; //密级 
		int m_DepartmentID; //文件单位 
		string m_DocType; //文件类型 
		int m_PageNumber; //页数 
		string m_Status; //状态 
		string m_Code; //Code 
		int m_HandleUserID; //持有人 
 
		protected string m_Tag; // 预定义属性 
		
		#endregion
		
		#region 构造函数 Constructors 
		public Document(){
					// m_ID = 0 ;
		// m_DocName = "" ;
		// m_Remark = "" ;
		// m_RegDate = System.DateTime.Now ;
		// m_UserID = 0 ;
		// m_SysSerialNumber = 0 ;
		// m_DocSerialNumber = "" ;
		// m_SecretLevel = "" ;
		// m_DepartmentID = 0 ;
		// m_DocType = "" ;
		// m_PageNumber = 0 ;
		// m_Status = "" ;
		// m_Code = "" ;
		// m_HandleUserID = 0 ;

		}
		//public Document(int ID,string DocName,string Remark,DateTime RegDate,int UserID,int SysSerialNumber,string DocSerialNumber,string SecretLevel,int DepartmentID,string DocType,int PageNumber,string Status,string Code,int HandleUserID, string Tag){
					// m_ID = ID ;
		// m_DocName = DocName ;
		// m_Remark = Remark ;
		// m_RegDate = RegDate ;
		// m_UserID = UserID ;
		// m_SysSerialNumber = SysSerialNumber ;
		// m_DocSerialNumber = DocSerialNumber ;
		// m_SecretLevel = SecretLevel ;
		// m_DepartmentID = DepartmentID ;
		// m_DocType = DocType ;
		// m_PageNumber = PageNumber ;
		// m_Status = Status ;
		// m_Code = Code ;
		// m_HandleUserID = HandleUserID ;

			//m_Tag = Tag;
		//}
		#endregion
		
		#region 公共属性成员 
		

		/// <summary>
		/// ID
		/// <summary>
		public int ID 
		{
                                         get { return m_ID; }
                                         set { m_ID = value;}
		}


		/// <summary>
		/// 文件标题
		/// <summary>
		public string DocName 
		{
                                         get { return m_DocName; }
                                         set { m_DocName = value;}
		}


		/// <summary>
		/// Remark
		/// <summary>
		public string Remark 
		{
                                         get { return m_Remark; }
                                         set { m_Remark = value;}
		}


		/// <summary>
		/// 处理日期
		/// <summary>
		public DateTime RegDate 
		{
                                         get { return m_RegDate; }
                                         set { m_RegDate = value;}
		}


		/// <summary>
		/// 责任人
		/// <summary>
		public int UserID 
		{
                                         get { return m_UserID; }
                                         set { m_UserID = value;}
		}


		/// <summary>
		/// 编号
		/// <summary>
		public int SysSerialNumber 
		{
                                         get { return m_SysSerialNumber; }
                                         set { m_SysSerialNumber = value;}
		}


		/// <summary>
		/// 发文字号
		/// <summary>
		public string DocSerialNumber 
		{
                                         get { return m_DocSerialNumber; }
                                         set { m_DocSerialNumber = value;}
		}


		/// <summary>
		/// 密级
		/// <summary>
		public string SecretLevel 
		{
                                         get { return m_SecretLevel; }
                                         set { m_SecretLevel = value;}
		}


		/// <summary>
		/// 文件单位
		/// <summary>
		public int DepartmentID 
		{
                                         get { return m_DepartmentID; }
                                         set { m_DepartmentID = value;}
		}


		/// <summary>
		/// 文件类型
		/// <summary>
		public string DocType 
		{
                                         get { return m_DocType; }
                                         set { m_DocType = value;}
		}


		/// <summary>
		/// 页数
		/// <summary>
		public int PageNumber 
		{
                                         get { return m_PageNumber; }
                                         set { m_PageNumber = value;}
		}


		/// <summary>
		/// 状态
		/// <summary>
		public string Status 
		{
                                         get { return m_Status; }
                                         set { m_Status = value;}
		}


		/// <summary>
		/// Code
		/// <summary>
		public string Code 
		{
                                         get { return m_Code; }
                                         set { m_Code = value;}
		}


		/// <summary>
		/// 持有人
		/// <summary>
		public int HandleUserID 
		{
                                         get { return m_HandleUserID; }
                                         set { m_HandleUserID = value;}
		}


		 
        /// <summary>
		/// 附加备用属性
		/// <summary>
		public string Tag {
			get { return m_Tag; }
			set { m_Tag = value; }
		}
		#endregion
		
        #region 扩展公共属性
		//-
		protected static string[] m_FiledsInfo=new string[]{
		  		"ID,int,ID",
		"DocName,varchar,文件标题",
		"Remark,varchar,Remark",
		"RegDate,smalldatetime,处理日期",
		"UserID,int,责任人",
		"SysSerialNumber,int,编号",
		"DocSerialNumber,varchar,发文字号",
		"SecretLevel,varchar,密级",
		"DepartmentID,int,文件单位",
		"DocType,varchar,文件类型",
		"PageNumber,int,页数",
		"Status,varchar,状态",
		"Code,varchar,Code",
		"HandleUserID,int,持有人",

		  "Tag,varchar,扩展备用属性" //注意该字段不存在于数据库表
		};
            
        /// <summary>
        /// 类对应的表结构信息,
        /// 记录 列的名称、数据类型和大小。
        /// </summary>
        public static string[] FiledsInfo {
            get {
                return m_FiledsInfo;
            }
        }
            

        /// <summary>
        /// 属性索引器
        /// </summary>
        /// <param name=\"index\"></param>
        /// <returns></returns>
        public object this[int index] {
            get {
                return this.getValue(m_FiledsInfo[index].Split(new char[] { ',' })[0]);
            }
            set {
                this.setValue(m_FiledsInfo[index].Split(new char[] { ',' })[0], value);
            }
        }
            
        /// <summary>
        /// 重载属性索引器
        /// </summary>
        /// <param name=\"name\"></param>
        /// <returns></returns>
        public object this[string name] {
            get {
                return this.getValue(name);
            }
            set {
                this.setValue(name, value);
            }
        }       
	 
        /// <summary>
        /// 根据属性名称赋值
        /// 请注意参数name必须完全等于类的某个属性，可以忽略大小写，
        /// </summary>
        /// <param name="name">属性名称</param>
        /// <param name="value">属性值</param>
        public void setValue(string name, object value)
        {
            PropertyInfo pinfo = this.GetType().GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            if (pinfo != null)
            {
                try
                {
                    pinfo.SetValue(this, Convert.ChangeType(value, pinfo.PropertyType), null);
                }
                catch
                {
                    throw new System.Exception("输入参数转换格式时出错！\n输入参数：" + value.ToString() + "\n转换格式：" + pinfo.PropertyType.ToString());
                }

            }
        }

        /// <summary>
        /// 根据属性名称取值
        /// 请注意参数name必须完全等于类的某个属性，可以忽略大小写，
        /// </summary>
        /// <param name="name">属性名称</param>
        public object getValue(string name)
        {
            PropertyInfo pinfo = this.GetType().GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            if (pinfo != null)
                return pinfo.GetValue(this, BindingFlags.IgnoreCase, null, null, null);
            else
                return null;
        }
        #endregion
			     
	}
}